<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="操作时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button icon="el-icon-download" size="mini" type="warning" @click="handleExportCurrentPage">当前页面导出</el-button>
        <el-button icon="el-icon-download" size="mini" type="danger" @click="handleExportAll">导出所有</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="list" v-loading="loading" max-height="700" style="flex: none;width: 100%"
    >
      <el-table-column
        prop="factorId"
        label="编号"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="stationName"
        label="来源站点"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="sid"
        label="站点编号"
        sortable
      >
      </el-table-column>

      <el-table-column
        prop="tem"
        label="站点温度"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="v50029"
        label="站点降水"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="prs"
        label="站点气压"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="rhu"
        label="站点湿度"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="win_D_Avg_2mi"
        label="站点风向"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="win_S_Avg_2mi"
        label="站点风速"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="stationLevel"
        label="站点等级"
        sortable
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.stationLevel === 1" type="success">国家站点</el-tag>
          <el-tag v-else type="warning">其他类型</el-tag>
        </template>

      </el-table-column>
      <el-table-column
        prop="createTime"
        label="获取时间"
        width="200"
        sortable
      ></el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import {getList} from "@/api/system/factor";
import moment from "moment";

export default {
  name: "Station",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      }
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    getDataList() {
      this.loading = true;
      this.queryParams.startTime = this.dateRange[0] ? moment(this.dateRange[0]).format('YYYYMMDDHHmm') : null
      this.queryParams.endTime = this.dateRange[1] ? moment(this.dateRange[1]).format('YYYYMMDDHHmm') : null
      getList(this.queryParams).then(response => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getDataList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
    },
    /**
     * 导出当前页面数据
     */
    handleExportCurrentPage() {
      this.queryParams.startTime = this.dateRange[0] ? moment(this.currentTime[0]).format('YYYYMMDDHHmm') : null
      this.queryParams.endTime = this.dateRange[1] ? moment(this.currentTime[1]).format('YYYYMMDDHHmm') : null
      this.download("factor/export", {
        ...this.queryParams
      }, `factor_${new Date().getTime()}.xlsx`)
    },
    /**
     * 导出所有数据
     */
    handleExportAll() {
      this.queryParams.startTime = this.dateRange[0] ? moment(this.currentTime[0]).format('YYYYMMDDHHmm') : null
      this.queryParams.endTime = this.dateRange[1] ? moment(this.currentTime[1]).format('YYYYMMDDHHmm') : null
      this.download("factor/exportAll", {
        ...this.queryParams
      }, `factorAll_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>

</style>
